<template>
  <div>
    <!--头 -->
    <div class="title">
      <el-breadcrumb>
        <el-breadcrumb-item>首页</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="tops">
      <div class="xiangyou" @click="returns">&lt;</div>
    </div>
    <!-- 详细信息 -->
    <div class="indes">
      <div class="indes_list">
        <div class="indes_one">
          <div class="indes_left">现有地址：</div>
          <div class="indes_right">
            <div style="line-height: 50px">{{ this.a }}</div>
            <div class="spans" @click="Updataw">修改</div>
          </div>
        </div>
        <div class="indes_one indes_ones">
          <div class="indes_left">现有联系人信息：</div>
          <div class="indes_right">
            <div class="ps">
              <p style="margin-top: 10px">电话：{{ this.b }}</p>
              <p>姓名：{{ this.c }}</p>
            </div>
            <div class="spans" @click="myphone">修改</div>
          </div>
        </div>
      </div>
    </div>
    <el-dialog title="收货地址" :visible.sync="dialogTableVisible">
      <el-form :model="form">
        <el-form-item>
          <el-input v-model="form.name" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="getmyads">确 定</el-button>
      </div>
    </el-dialog>

    <el-dialog title="修改详细信息" :visible.sync="dialogTableVisibles">
      <el-form :model="form">
        <el-form-item label="联系人姓名：" :label-width="formLabelWidth">
          <el-input v-model="form.myname" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="联系人电话：" :label-width="formLabelWidth">
          <el-input v-model="form.phone" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="getadd">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getNotice, uPnavicons } from '../../api/index'
export default {
  data() {
    return {
      a: '',
      b: '',
      c: '',
      lists: [],
      dialogTableVisible: false,
      dialogTableVisibles: false,
      form: {
        name: '',
        myname: '',
        phone: '',
      },
      formLabelWidth: '120px',
    }
  },
  created() {
    this.userna()
  },
  methods: {
    //更新用户信息
    getadd() {
      if (this.form.phone != '' && this.form.myname) {
        uPnavicons({
          id: 1,
          myname: this.form.myname,
          phone: this.form.phone,
        }).then(() => {
          ;(this.dialogTableVisibles = false), (this.form.phone = ''), (this.form.myname = '')
          this.userna()
        })
      }
    },
    myphone() {
      this.dialogTableVisibles = true
    },
    //更新用户地址
    getmyads() {
      if (this.form.name != '') {
        uPnavicons({
          id: 1,
          address: this.form.name,
        }).then(() => {
          this.dialogTableVisible = false
          ;(this.form.name = ''), this.userna()
        })
      }
    },
    Updataw() {
      this.dialogTableVisible = true
    },
    //获取用户信息
    userna() {
      getNotice().then((res) => {
        ;(this.lists = res.data), (this.a = this.lists[0].address), (this.b = this.lists[0].phone), (this.c = this.lists[0].myname)
      })
    },
    //跳转路由
    returns() {
      this.$router.push({
        name: 'index',
      })
    },
  },
}
</script>

<style lang="scss" scoped>
.title {
  margin-bottom: 10px;
}
//头部
.tops {
  width: 100%;
  height: 40px;
  display: flex;
  line-height: 40px;
  text-indent: 20px;
  .xiangyou {
    font-size: 20px;
    cursor: pointer;
  }
}
.indes {
  width: 100%;
  height: 200px;
  // background: salmon;
  padding: 40px;
  box-sizing: border-box;
  .indes_list {
    width: 400px;
    height: 100px;
    border: 1px solid #ddd;
    .indes_one {
      width: 100%;
      height: 50%;
      border-bottom: 1px solid #ddd;
      display: flex;
      position: relative;
      .indes_left {
        width: 200px;
        height: 100%;
        text-align: center;
        line-height: 50px;
        border-right: 1px solid #ddd;
      }
      .indes_right {
        width: 100%;
        height: 100%;
        text-indent: 20px;
      }
    }
    .indes_ones {
      border: 0;
    }
  }
}

.spans {
  width: 60px;
  height: 30px;
  position: absolute;
  right: 20px;
  top: 10px;
  border: 1px solid #ddd;
  line-height: 30px;
}
</style>
